import numpy as np
import datasets
import evaluate


class Accuracy(evaluate.Metric):
    def _info(self):
        return evaluate.MetricInfo(
            description="",
            citation="",
            inputs_description="",
            features=datasets.Features(
                {
                    "predictions": datasets.Sequence(datasets.Value("int32")),
                    "references": datasets.Sequence(datasets.Value("int32")),
                }
                if self.config_name == "multilabel"
                else {
                    "predictions": datasets.Value("int32"),
                    "references": datasets.Value("int32"),
                }
            ),
            reference_urls=[],
        )

    def _compute(self, predictions, references):
        return {
            "accuracy": sum(np.array(predictions) == np.array(references))
            / len(references)
        }
